<template>
  <el-row style="width: 100%">
    <el-col class="left" :span="18">
      <i class="el-icon-s-home"></i>
      <span>{{ item.name }}</span>
    </el-col>
    <el-col class="right" :span="6">
      <span>{{ item.manager }}</span>
      <el-dropdown @command="mycommand">
        <span class="el-dropdown-link">
          操作<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item v-if="!item.isHead" command="edit" 
            >查看部门</el-dropdown-item
          >
          <el-dropdown-item v-if="!item.isHead" command="del"
            >删除部门</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { delDeptApi } from "@/api/departments";
export default {
  // 接收外界传入的一个参数：
  //  label：用来显示当前子节点的文本
  // data() {
  //   return {
  //     command:''
  //   }
  // },
  props: ["item"],
  methods: {
    mycommand(command) {
      // 新增
      if (command === "add") {
        this.$emit("addShow", this.item.id);
        // 修改
      } else if (command === "edit") {
        this.$emit("editShow",this.item.id);
        // 删除
      } else if (command === "del") {
        // 询问是否删除
        this.$confirm("是否确定删除当前部门", "警告")
          .then(async () => {
            const res = await delDeptApi(this.item.id);
            console.log(res);
            alert(res.message);
            // 更新数据
            this.$emit("updateData");
          })
          .catch();
      }
    },
  },
};
</script>

<style></style>
